tool
extends TileMap
var noise = OpenSimplexNoise.new()#柏林噪声
var data = {}
#数据结构data[x][y] == 地形数据
func _ready():
	initialization()
	var xx = {}
	for x in 100:
		var yy = {}
		for y in 100:
			yy[y] = (map_data_generation(x,y))
		xx[x] = (yy)
	data[0] = (xx)
	map_data_write_archive()
	pass # Replace with function body.
#初始化柏林噪声
func initialization():
	noise.seed = randi()
	noise.octaves = 4
	noise.period = 40.0
	noise.persistence = 0.8
#地图数据数据生成
func map_data_generation(x:int,y:int):
	var i = (int(noise.get_noise_2d(x, y)*100))
	var da = 0
	if (i < -20):
		da = 1
		set_cell(x,y,1)
	elif (i < -10):
		da = 0
		set_cell(x,y,0)
	elif (i < 0):
		da = 3
		set_cell(x,y,3)
	else:
		da = 2
		set_cell(x,y,2)
	return da
#地图数据存档写入
func map_data_write_archive():
	var map = File.new()
	map.open("user://savemap.save", File.WRITE)
	map.store_var(data);
	map.close();
#地图数据存档读取
func map_data_read_archive():
	var map = File.new()
	map.open("user://savemap.save", File.READ)
	data = map.get_var();
	map.close();
